var a = require("../../../../@babel/runtime/helpers/defineProperty"), t = require("../../../../@babel/runtime/helpers/toConsumableArray"), s = getApp();

Page({
    data: {
        language: "",
        selected: 0,
        display: "-1",
        _status: "",
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        statusData0: [],
        statusData1: [],
        statusData2: [],
        statusData3: [],
        open_order_buyer: "",
        open_order_detail: "",
        open_order_buyer_info: ""
    },
    onLoad: function(a) {
        this.setData({
            selected: a.selected || 0
        }), this._swichTabData();
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {
        this.customizeIncome();
    },
    customizeIncome: function() {
        try {
            var a = wx.getStorageSync("mailLanguage");
            if (a) {
                var t = JSON.parse(a);
                wx.setNavigationBarTitle({
                    title: t.commission.commission_order ? t.commission.commission_order : "分销订单"
                });
            }
        } catch (a) {}
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : wx.showToast({
            title: "没有更多数据",
            icon: "none"
        });
    },
    onShareAppMessage: function() {},
    swichTab: function(a) {
        var t = a.detail.index;
        this.setData({
            selected: t
        }), this._swichTabData();
    },
    _swichTabData: function() {
        this.setData({
            display: "-1"
        }), 0 == this.data.selected ? this.getData("") : 1 == this.data.selected ? this.getData(0) : 2 == this.data.selected ? this.getData(1) : 3 == this.data.selected && this.getData(3);
    },
    getData: function(a) {
        this.setData({
            _status: a
        });
        var t = this, e = s.getNetAddresss("plugin.commission.api.commission.get-commission-orders");
        e += "&status=" + a, s._getNetWork({
            url: e,
            success: function(s) {
                var e = s.data;
                if (1 == e.result) {
                    for (var i = 0; i < e.data.orders.data.length; i++) e.data.orders.data[i].display = !1;
                    "" === a ? t.setData({
                        statusData0: e.data.orders.data
                    }) : 0 === a ? t.setData({
                        statusData1: e.data.orders.data
                    }) : 1 === a ? t.setData({
                        statusData2: e.data.orders.data
                    }) : 3 === a && t.setData({
                        statusData3: e.data.orders.data
                    }), t.setData({
                        total_page: e.data.orders.last_page,
                        isLoadMore: !0,
                        page: e.data.orders.current_page,
                        open_order_buyer: e.data.set.open_order_buyer,
                        open_order_detail: e.data.set.open_order_detail,
                        open_order_buyer_info: e.data.set.open_order_buyer_info
                    });
                }
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getMoreData: function() {
        var a = this, e = {};
        if (this.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.total_page)) {
            var i = this.data.page;
            i += 1, this.setData({
                page: i
            }), e.page = this.data.page, e.status = this.data._status;
            var d = s.getNetAddresss("plugin.commission.api.commission.get-commission-orders");
            s._getNetWork({
                url: d,
                data: e,
                success: function(s) {
                    a.setData({
                        isLoadMore: !0
                    });
                    var e = s.data;
                    if (1 == e.result) {
                        for (var i = 0; i < e.data.orders.data.length; i++) e.data.orders.data[i].display = !1;
                        var d = [];
                        "" === a.data._status ? (d = [].concat(t(a.data.statusData0), t(e.data.orders.data)), 
                        a.setData({
                            statusData0: d
                        })) : 0 === a.data._status ? (d = [].concat(t(a.data.statusData1), t(e.data.orders.data)), 
                        a.setData({
                            statusData1: d
                        })) : 1 === a.data._status ? (d = [].concat(t(a.data.statusData2), t(e.data.orders.data)), 
                        a.setData({
                            statusData2: d
                        })) : 3 === a.data._status && (d = [].concat(t(a.data.statusData3), t(e.data.orders.data)), 
                        a.setData({
                            statusData3: d
                        })), a.setData({
                            isLoadMore: !0
                        });
                    } else {
                        var o = a.data.page;
                        o -= 1, a.setData({
                            page: o,
                            isLoadMore: !1
                        });
                    }
                }
            });
        }
    },
    toggle: function(t) {
        var s = t.currentTarget.dataset.idx;
        0 == this.data.selected ? this.data.statusData0[s].display ? this.setData(a({}, "statusData0[" + s + "].display", !1)) : this.setData(a({}, "statusData0[" + s + "].display", !0)) : 1 == this.data.selected ? this.data.statusData1[s].display ? this.setData(a({}, "statusData1[" + s + "].display", !1)) : this.setData(a({}, "statusData1[" + s + "].display", !0)) : 2 == this.data.selected ? this.data.statusData2[s].display ? this.setData(a({}, "statusData2[" + s + "].display", !1)) : this.setData(a({}, "statusData2[" + s + "].display", !0)) : 3 == this.data.selected && (this.data.statusData3[s].display ? this.setData(a({}, "statusData3[" + s + "].display", !1)) : this.setData(a({}, "statusData3[" + s + "].display", !0)));
    }
});